package com.dev;
import android.widget.LinearLayout;
import java.io.File;
public class SimpleFileBrowser extends LinearLayout{
	File[] willshow;
	MainActivity ma;
	int sort;
    SimpleFileBrowser(MainActivity ma){
		super(ma);
		this.ma=ma;
	}
    void setWillshow(File[] willshow){
		if(sort==0){
			this.willshow=willshow;
		}else if(sort==1){
			sortByName(willshow);
			this.willshow=willshow;
		}else if(sort==2){
			sortByNameReverse(willshow);
			this.willshow=willshow;
		}
	}
    void sortByName(File[] fs){
		String[] fs_names=new String[fs.length];
		for(int index=0;index<fs.length;index++){
			fs_names[index]=fs[index].getName();
		}
		for(int index=0,end=fs.length-1;true;index++){
			if(index<end){
				String name1=fs_names[index];
				String name2=fs_names[index+1];
				if(name1.compareTo(name2)>0){
					File f=fs[index];
					String s=fs_names[index];
					fs[index]=fs[index+1];
					fs[index+1]=f;
					fs_names[index]=fs_names[index+1];
					fs_names[index+1]=s;
				}
			}else if(--end>0){
				index=0;
				continue;
			}else{
				break;
			}
		}
	}
	void sortByNameReverse(File[] fs){
		String[] fs_names=new String[fs.length];
		for(int index=0;index<fs.length;index++){
			fs_names[index]=fs[index].getName();
		}
		for(int index=0,end=fs.length-1;true;index++){
			if(index<end){
				String name1=fs_names[index];
				String name2=fs_names[index+1];
				if(name1.compareTo(name2)<0){
					File f=fs[index];
					String s=fs_names[index];
					fs[index]=fs[index+1];
					fs[index+1]=f;
					fs_names[index]=fs_names[index+1];
					fs_names[index+1]=s;
				}
			}else if(--end>0){
				index=0;
				continue;
			}else{
				break;
			}
		}
	}
}
